package com.dayaokeji.rhythmschoolstudent.client.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.BaseActivity;

import butterknife.BindView;

/**
 * 会议历史
 */
public class MeetingSearchActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.et_search)
    EditText etSearch;

    private MeetingSearchListFragment meetingHistoryListFragment;

    public static void navigation(Context context) {
        Intent intent = new Intent(context, MeetingSearchActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meeting_search);
        setSupportActionBar(toolbar);

        init();
    }

    private void init() {
        final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        meetingHistoryListFragment = MeetingSearchListFragment.newInstance();
        fragmentTransaction.replace(R.id.content,meetingHistoryListFragment);
        fragmentTransaction.commit();

        setOnListener();
    }

    private void setOnListener() {
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (meetingHistoryListFragment != null) {
                    meetingHistoryListFragment.queryKeyword(s.toString());
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
}
